package demo;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * @author yuyufeng
 * @date 2017/10/30
 */
public class FileHander {
    /**
     * {
     * "distributorCode": "XCLY",
     * "url":" http://ota.bababus.com/partner/getRealRegularBuses.htm",
     * "sign":"TcDDcdjpQOiYKt4OvcmITdkkJxS32FzC75v/prfW8g41K1eNBZO45vKn5Hj34r5I0KCKB3sI+F4d51SfCvf3S5yAEjR4kECqR//XtHjuulQD6qiLA23ut53ELg2z3NkVvfhfIoGBAXK+EUHXrzWnc6Ox90UgRmoHu9ch3L2BOcQ=",
     * "data":{"header":{"version":"1.0","type":"1","operateCode":"000"},"body":{"departurePlacename":"新昌","arrivalPlacename":"杭州","departureDate":"2017-06-03"}}
     * <p>
     * }
     *
     * @param args
     * @throws IOException
     */
    //Entire running time(millis)=[278] in http://ota.bababus.com/partner/getRealRegularBuses.htm [distributorCode=XCLY]
    // [sign=b/FMX8AEMOL+GvTYjEKpLwNS837HHSlXFieFd2AlQ57nFR+worx+NOgSWGKoYNBfh6klNjG88O8ejhl0H6NYrvOle6K5nsoMdu7L+EYR+Fy03oQboI0Dv5FLEy7A5TLtfg5dlqqVB4Hbj6SzpRn6v3BJ2aCj9kD6yRLDStRBBJY=]
    // [data={"header":{"version":"1.0","type":"1","operateCode":"000"},"body":{"departurePlacename":"华埠","arrivalPlacename":"遂昌","departureDate":"2017-06-27"}}]
    public static void main(String[] args) throws IOException {
        String file = "H://profler2.log";
        BufferedReader bf = new BufferedReader(new FileReader(file));
        String str = null;
        while ((str = bf.readLine()) != null) {
            if (str.indexOf("distributorCode") != -1) {
                String distributorCode = str.substring(str.indexOf("distributorCode") + 16, str.indexOf("]", str.indexOf("distributorCode")));
                String url = str.substring(str.indexOf("http://"), str.indexOf(".htm") + 4);
                String sign = str.substring(str.indexOf("sign=") + 5, str.indexOf("]", str.indexOf("sign=")) - 1);
                String data = str.substring(str.indexOf("data=") + 5, str.indexOf("]", str.indexOf("[data=")) - 1);
                String json = "{" +
                        "'distributorCode':'" + distributorCode +
                        "','url':" + url +
                        "','sign':'" + sign +
                        "','data':'" + data +
                        "}";
                System.out.println(json);
            }
        }
    }
}
